home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / RCShaders / RCShadowSpot.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  984 b   |  31 lines

  1. /* Listing 16.33  Spotlight using shadow map*/
  2. /*
  3.  *  shadowspot(): spotlight with an optional shadow map
  4.  */
  5. light
  6. RCShadowSpot( 
  7.     float    intensity    = 1;
  8.     color    lightcolor    = 1;
  9.     point    from        = point 0,    /* light position */
  10.         to        = point (0,0,1);
  11.     float    coneangle    = radians(30),
  12.         conedeltaangle    = radians(5),
  13.         beamdistribution= 2;
  14.     string    shadowfile    = "" )
  15. {
  16.     uniform point A = (to - from) / length(to - from); /* direction */
  17.     uniform float    cosoutside= cos(coneangle),
  18.             cosinside = cos(coneangle-conedeltaangle);
  19.     float    attenuation,     /* falloff from center of illumination cone */
  20.         cosangle;    /* cosine of angle wrt center of cone */
  21.  
  22.     illuminate( from, A, coneangle ) {
  23.         cosangle = L.A / length(L);    /* A is already normalized */
  24.         attenuation = pow(cosangle, beamdistribution) / (L.L);
  25.         attenuation *= smoothstep( cosoutside, cosinside, cosangle );
  26.         if( shadowfile != "" )
  27.             attenuation *= (1.0 - shadow( shadowfile, Ps ));
  28.         Cl = attenuation * intensity * lightcolor;
  29.     }
  30. }
  31.